#!/usr/bin/env bash -e 

GORAY_REV=7a4dba578a56
SINGLE_FILE_PACKAGES="
	all.go
	cameras/ortho.go
	cameras/perspective.go
	integrators/directlight.go
	integrators/trivial.go
	integrators/util.go
	lights/point.go
	lights/spot.go
	materials/common.go
	materials/debug.go
	materials/shinydiffuse.go
"

# Check out required external packages.
hg -q clone https://goauth2.googlecode.com/hg goauth2.googlecode.com/hg
hg -q clone https://goyaml.googlecode.com/hg goyaml.googlecode.com/hg
hg -q clone -u $GORAY_REV https://bitbucket.org/zombiezen/goray goray-tmp
mv goray-tmp/src/goray goray
rm -rf goray-tmp

# Put single-file packages into their own directories.
for fn in $SINGLE_FILE_PACKAGES; do
	fn=goray/std/$fn
	dir=$(echo $fn | sed 's/\.go//')
	mkdir $dir
	mv $fn $dir
done

# Remove unnecessary packages.
rm -rf goauth2.googlecode.com/hg/oauth/example \
	goray/std/objects/mesh/intersect_{amd64.s,decl.go} \
	goray/server

echo "Done"
